package member.memberjoin;
import java.io.*;
import java.sql.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import db.member.*;
public class MemberJoin extends HttpServlet{
	public void doPost(HttpServletRequest request,
			  HttpServletResponse response){
			  try {
				  requestPro(request,response);
			   } catch (Exception e) {
			    e.printStackTrace();
			   } 
			 }
	 public void doGet(HttpServletRequest request,
	  HttpServletResponse response){
	  try {requestPro(request,response);
	   } catch (Exception e) {
	    e.printStackTrace();
	   }
	 }
	 
	 public void requestPro(HttpServletRequest request,
			  HttpServletResponse response) throws Exception{
			  MemberDAO dao=new MemberDAO();
			  MemberBean bean=new MemberBean();
			  boolean a=false;
			  request.setCharacterEncoding("UTF-8");
			  
			  bean.setShop_id(request.getParameter("shop_id"));
			  bean.setShop_pswd(request.getParameter("shop_pswd"));
			  bean.setShop_name(request.getParameter("shop_name"));
			  bean.setShop_phon(request.getParameter("shop_phon01")+"-"+
					  			request.getParameter("shop_phon02")+"-"+
					  			request.getParameter("shop_phon03"));
			  bean.setShop_bir_y(Integer.parseInt(request.getParameter("shop_bir_y")));
			  bean.setShop_bir_d(Integer.parseInt(request.getParameter("shop_bir_d")));
			  bean.setShop_bir_m(Integer.parseInt(request.getParameter("shop_bir_m")));
			  bean.setShop_sex(request.getParameter("shop_sex"));
			  bean.setShop_zipcode(request.getParameter("shop_zipcode1")+ " - " +
					               request.getParameter("shop_zipcode2"));
			  bean.setShop_add01(request.getParameter("shop_add01"));
			  bean.setShop_add02(request.getParameter("shop_add02"));
			  bean.setShop_mail(request.getParameter("shop_mail01")+"@"+
			                    request.getParameter("shop_mail02"));
			  bean.setShop_mail_service(request.getParameter("shop_mail_service"));
			  bean.setShop_date(new Timestamp(System.currentTimeMillis()));
			  
			  a=dao.empJoin(bean);
			  
			  if(a==true){
			  response.setContentType("text/html; charset=UTF-8");
				PrintWriter out = response.getWriter();
				out.println("<script>");
				out.println("alert('회원가입 성공 로인해주세요.');");
				out.println("location.href='./harvest/index.jsp';");
				out.println("</script>");			
				out.close();
			  }else{
				  response.setContentType("text/html; charset=UTF-8");
					PrintWriter out = response.getWriter();
					out.println("<script>");
					out.println("alert('회원가입에 실패하셨습니다.');");
					out.println("location.href=login.jsp';");
					out.println("</script>");			
					out.close(); 
			  }
		}
}
